<script src="js/Calendar.js" type="text/javascript"></script>
<script type="text/javascript" src="js/global/Date_func.js"></script>
<link rel="stylesheet" type="text/css" href="css/member.css"/>
<style>
	.report{margin:10px 0; padding:15px; border:1px solid #eee}
	.report span.part{ margin-right:20px;}
	input.time{    background: url("images/rili.png") no-repeat scroll right center #FFFFFF;
    border: 1px solid #7F9DB9;
    height: 20px;
    line-height: 20px;
    width: 120px;}
	.total{ width:100%; text-align:center;}
	input.checkbox{ vertical-align:-2px; margin-right:2px;}
	.btn{ background:#eee; padding:4px 15px; *padding:4px 8px; background:url("images/mc_title.png") no-repeat right top; color:#fff; border:none; cursor:pointer}
	#excel{margin-left:10px;}
</style>
<h3 class="mc_title">
	<span class="mctit_1 <?=($from!="sale")?"notcur":""?>">
		<a href="orderReport.html"><span class="mctit_2">已卖出产品报表</span></a>
	</span>
	<?if($_a->checkAuth("buyOrderReport.html")){?>
	<span class="mctit_1 <?=($from=="sale")?"notcur":""?>">
		<a href="buyOrderReport.html"><span class="mctit_2">已买到产品报表</span></a>
	</span>
	<?}?>
</h3>
<form class="report" method="get">
	<input type="hidden" name="proList" value='<?=$proList?>'/>
	<input type="hidden" name="act" id="act" value=""/>
	<p>
		<span class="part">
			<label>
                <!--交易日期：-->
                <select name="time_type" id="time_type">
                    <option value="1" <?=$_REQUEST['time_type']==1?'selected' :''?>>下单时间</option>
                    <option value="2" <?=$_REQUEST['time_type']==2?'selected' :''?>>预计游玩</option>
                    <option value="3" <?=$_REQUEST['time_type']==3?'selected' :''?>>完成时间</option>
                </select>
            </label>
			<input type="text" name="begintime" id="begintime" class="time" value="<?=$btime?>" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)"/>
			<label>至</label>
			<input type="text" name="endtime" id="endtime" class="time" value="<?=$etime?>" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)"/>
			<a href="javascript:changeDate('today');" class="sDate">今天</a>
			<a href="javascript:changeDate('yesterday');" class="sDate">昨天</a>
			<a href="javascript:changeDate('week');" class="sDate">本周</a>
			<a href="javascript:changeDate('lastweek');" class="sDate">上周</a>
			<a href="javascript:changeDate('month');" class="sDate">本月</a>
			<a href="javascript:changeDate('lastmonth');" class="sDate">上月</a>
		</span>
		<input type="submit" class="btn" value="查 询"/>
		<input type="button" id="excel" class="btn" value="导 出"/>
	</p>
	<p style="margin:10px 0;">
	订单状态：
	<span  class="part">
		<input class="checkbox" type="checkbox" name="status[]" <?=in_array("0|1|2|3|5|6",$_REQUEST['status'])?"checked":""?> value="0|1|2|3|5|6"/><label>全部</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=in_array("0|6",$_REQUEST['status'])?"checked":""?> value="0|6"/><label>未使用</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=(in_array("1",$_REQUEST['status']) ||$_REQUEST['time_type']==3)?"checked":""?> value="1"/><label>已使用</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=(in_array("2",$_REQUEST['status'])&& $_REQUEST['time_type']!=3)?"checked":""?> value="2"/><label>已过期</label>
		<input class="checkbox" type="checkbox" name="status[]" <?=(in_array("3|5",$_REQUEST['status']) && $_REQUEST['time_type']!=3)?"checked":""?> value="3|5"/><label>已取消</label>
	</span>
	<span  class="part">
		统计方式：
		<select name="by">
			-<option value="">统计方式</option>
			<option value="lid" <?=($_REQUEST['by']=="lid")?"selected":""?>>按景区统计</option>
			<option value="tid" <?=($_REQUEST['by']=="tid")?"selected":""?>>按门票统计</option>
			<option value="buyid" <?=($_REQUEST['by']=="buyid")?"selected":""?>>按分销商统计</option>
		</select>
	</span>
	</p>
    <p style="margin:10px 0;">
		<span  class="part">
            景点：
            <select name="landid" id="land">
                <option value="">--选择--</option>
				<?foreach($products as $k => $v):?>
                <option value="<?=$k?>" <?=($_REQUEST['landid']==$k)?"selected":""?>><?=$v?></option>
				<?endforeach;?>
            </select>
        </span>
		<span  class="part">
            门票：
            <select name="ticket" id="ticket">
                <option value="">--选择--</option>
				<?
					if(isset($_REQUEST['landid']) && !empty($_REQUEST['landid'])){
						$sql='SELECT id,title FROM uu_jq_ticket WHERE landid='.($_REQUEST['landid']+0);//
						$GLOBALS['le']->query($sql);
						$tickes = array();
						while($row=$GLOBALS['le']->fetch_assoc()){
							$tickes[]=$row;
						}
						if(count($tickes)){
							$html = '';
							foreach($tickes as $v){
							
								$title= $v['title'];
								$vs=$v['id'].'_'.$title;
								if(isset($_REQUEST['ticket']) && !empty($_REQUEST['ticket']) && $_REQUEST['ticket']==$vs){
									$html.="<option value='{$vs}' selected='selected'>{$title}</option>";
								}else{
									$html.="<option value='{$vs}'>{$title}</option>";
								}
							}
							echo $html;
						}
					}
				?>
            </select>
        </span>
		<?if(isset($DistorsNames) && count($DistorsNames)>0):?>
			<?if($from == 'sale'):?>
            <span  class="part">
            <?=$dTypeName?>：<?=GetHtmlSelect($DistorsNames, 'fid', $fid, array('k'=>0,'v'=>'--分销商--'))?>
            </span>
			<?else:?>
			<span  class="part">
            <?=$dTypeName?>：<?=GetHtmlSelect($DistorsNames, 'aid', $aid, array('k'=>0,'v'=>'--供应商--'))?>
            </span>
			<?endif;?>
        <?endif;?>
    </p>
</form>
<div class="rank">
	<div class="rankcon">
		<table class="ranktab">
			<thead id="rankhd">
				<th>序号</th>
				<th class="tL"><?=$titleT[$by]?></th>
				<th><span class="sort" onclick="sortTable('offmain',2, true ,this);">订单数量</span></th>
				<th><span class="sort" onclick="sortTable('offmain',3, true ,this);">门票数量</span></th>
				<th><span class="sort" onclick="sortTable('offmain',4, true ,this);">金额</span></th>
				<th><span class="sort" onclick="sortTable('offmain',5, true ,this);">余额支付</span></th>
				<th><span class="sort" onclick="sortTable('offmain',6, true ,this);">在线支付</span></th>
				<th><span class="sort" onclick="sortTable('offmain',7, true ,this);">授信支付</span></th>
				<th><span class="sort" onclick="sortTable('offmain',8, true ,this);">产品自销</span></th>
				<th><span class="sort" onclick="sortTable('offmain',8, true ,this);">现场支付</span></th>
			</thead>
			<tbody id="offmain">
				<?foreach($r as $lid=>$row){
					$totals['order']+=$row['order'];
					$totals['tnum']+=$row['tnum'];
					$totals['money']+=$row['money']/100;
					$totals['pmode0']+=$row['pmode0']/100;
					$totals['pmode1']+=$row['pmode1']/100;
					$totals['pmode2']+=$row['pmode2']/100;
					$totals['pmode3']+=$row['pmode3']/100;
					$totals['pmode4']+=$row['pmode4']/100;
				?>
				<tr data-id="">
					<td><?=++$n?></td>
					<td class="tL"><?=$row['title']?></td>
					<td><?=$row['order']?></td>
					<td><?=$row['tnum']?></td>
					<td><?=$row['money']/100?></td>
					<td><?=$row['pmode0']/100?></td>
					<td><?=$row['pmode1']/100?></td>
					<td><?=$row['pmode2']/100?></td>
					<td><?=$row['pmode3']/100?></td>
					<td><?=$row['pmode4']/100?></td>
				</tr>
				<?}?>
			</tbody>
			<tfoot>
			<?if(count($r)>0):?>
				<tr>
					<td  colspan="2">总计：</td>
					<td><?=$totals['order']?></td>
					<td><?=$totals['tnum']?></td>
					<td><?=$totals['money']?></td>
					<td><?=$totals['pmode0']?></td>
					<td><?=$totals['pmode1']?></td>
					<td><?=$totals['pmode2']?></td>
					<td><?=$totals['pmode3']?></td>
					<td><?=$totals['pmode4']?></td>
				</tr>
			<?else:?>
				<tr>
					<td align="left" colspan="9">&nbsp;&nbsp;&nbsp;交易日期无销售订单！</td>
				</tr>
			<?endif?>
			</tfoot>
		</table>
	</div>
</div>
<script src="js/jsorder.js"></script>
<script src="js/jsorder.js"></script>
<script>
	$("#time").change(function(){
		Date_func.selectDate($(this).val(),$("#begintime").get(0),$("#endtime").get(0));
	});
	$("input.btn").click(function(){
		var btime=$("#begintime").val();
		var etime=$("#endtime").val();
		btime=btime.split("-");
		etime=etime.split("-");
		month=(etime[0]-btime[0])*12+(etime[1]-btime[1]);
		if(month>3){
			alert("交易日期时间间隔不能超过三个月");
			return false;
		}
	});
	// 获取门票
	$("#land").change(function(){
		
		landid=$(this).val();
		if(landid==''){
			_options = '<option value="">--选择--</option>';
			$("#ticket").html(_options);
			return;
		}
		$.ajax({
			uri:window.location.href,
			data:"landid="+landid,
			beforeSend:function (XMLHttpRequest) {
				XMLHttpRequest.setRequestHeader("request_type","getTicket");
			},
			success: function(data){
				data = JSON.parse(data);
				if(data.s=='success'){
					_options = '<option value="">--选择--</option>';
					for(var i in data.content){
						_options+='<option value="'+data.content[i].id+'_'+data.content[i].title+'">'+data.content[i].title+'</option>';
					}
					$("#ticket").html(_options);

				}
			}
		});
	});
	
	$("#excel").click(function(){
		$("#act").val("orderReportExcel");
		$("form.report").submit();
		$("#act").val("");
	});
	
	function changeDate(date){
		// lastweek颠倒了
		if(date=='lastweek'){
			Date_func.selectDate(date,$("#endtime").get(0),$("#begintime").get(0));
		}else{
			Date_func.selectDate(date,$("#begintime").get(0),$("#endtime").get(0));
		}
	}
</script>